/**
 * 框架定义的默认路由和路由守护
 *
 * 请不要修改!
 */

import { NavigationGuardNext, Route, RouteConfig } from "vue-router";
import Vue from "vue";
import { PermissionTool } from "@/utils/frame/PermissionTool";

// 自定义特殊路由页面
const layoutRoute: RouteConfig[] = [
  {
    // 所有找不到的页面都跳转到404
    path: "*",
    redirect: "404"
  }
];

// 自定义路由开始前操作
const beforeGrad = function(
  to: Route,
  from: Route,
  next: NavigationGuardNext<Vue>
) {
  console.log("[ROUTE:]", to);
  if (to.name == "403") {
    next();
  } else {
    // 判断路由的权限
    if (
      PermissionTool.hasPermission(
        PermissionTool.getRoutePermissionCode(to.name!)
      )
    ) {
      next();
    } else {
      next("403");
    }
  }
};

export default {
  layoutRoute,
  beforeGrad
};
